<?php

namespace app\api\controller;

use app\admin\model\ad\Ad;
use app\admin\model\article\Message;
use app\admin\model\article\OnlineVideo;
use app\admin\model\article\Works;
use app\common\controller\Api;

/**
 * 首页接口
 * @ApiWeigh (10)
 */
class Index extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];

    /**
     * 首页
     * @ApiMethod (POST)
     * @ApiReturnParams   (name="adList", type="object", required=true, description="首页轮播")
     * @ApiReturnParams   (name="messageList", type="object", required=true, description="消息列表")
     * @ApiReturnParams   (name="worksList", type="object", required=true, description="优秀作品列表")
     * @ApiReturnParams   (name="onlineVideoList", type="object", required=true, description="线上视频列表")
     * @ApiReturnParams   (name="storeImage", type="string", required=true, description="门店图片")
     * @ApiReturnParams   (name="teacherImage", type="string", required=true, description="教师资历图片")
     */
    public function index()
    {
        //轮播
        $adList = Ad::where("type", Ad::TYPE_PLATFORM_HEADER)
            ->where("switch", 1)
            ->order("weigh", "desc")
            ->select();
        foreach ($adList as $key => $value){
            $value["image"] = deal_img_url($value["image"]);
        }
        //公告消息
        $messageModel = new Message();

        $messageList = $messageModel->getList([],$this->auth->getUser(),0,10);
        //门店图片
        $store_image = deal_img_url(config("site.miniapp_index_store_image"));
        //教师资历图片
        $teacher_image = deal_img_url(config("site.miniapp_index_teacher_image"));
        //优秀作品
        $worksModel = new Works();
        $worksList = $worksModel->getList([],0,10);
        //线上视频列表
        $onlineVideoModel = new OnlineVideo();
        $onlineVideoList = $onlineVideoModel->getList([],0,10);

        //课程
        $courseModel = new \app\admin\model\course\Course();
        $courseCondition = [
            "is_recommend" => 1
        ];
        $courseList = $courseModel->getList($courseCondition,0,6);
        //拼团
        $spellModel = new \app\admin\model\course\Spell();
        $spellCondition = [
            "spell.is_recommend" => 1
        ];
        $spellList = $spellModel->getList($spellCondition,0,3);
        $res = [
            "adList" => $adList,
            "messageList" => $messageList,
            "storeImage" => $store_image,
            "teacherImage" => $teacher_image,
            "worksList" => $worksList,
            "onlineVideoList" => $onlineVideoList,
            "spellList" => $spellList,
            "courseList" => $courseList,
        ];
        $this->success('请求成功', $res);
    }

    /**
     * 获取信息
     * @ApiMethod (POST)
     * @ApiParams   (name="course_id", type="object", required=true, description="课程id")
     */
    public function getCommonInfo()
    {
        $course_id = $this->request->post("course_id",0);
        $res = [
            "wechat_url" => \app\admin\model\User::getWechatUrl($course_id)
        ];
        $this->success('请求成功', $res);
    }
}
